<template>
    <div id="app_login">
        <div class="top">
            <span>登录</span>
            <router-link to="/view_register">注册</router-link>
        </div>
        <ul class="nav nav-tabs" id="myTab" role="tablist">
            <li class="nav-item" role="presentation">
                <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">账号密码登录</a>
            </li>
            <li class="nav-item" role="presentation">
                <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">手机号快速登录</a>
            </li>
        </ul>
        <div class="tab-content" id="myTabContent">
            <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
                <div class="content">
                    <!--<p>地区：<input type="text" placeholder="请选择地区"  autofocus></p>-->
                    <p><label for="username">账号：</label>
                        <input type="text" name="username" v-model="username" id="username" placeholder=" 请输入用户名"></p>
                    <p><label for="pwd">密码：</label>
                        <input type="password" name="pwd" id="pwd" v-model="pwd" placeholder=" 请输入6-12位密码"></p>
                    <p><button @click="login()">登录</button></p>
                    <!--<p><router-link to="">忘记密码？</router-link></p>-->
                </div>
            </div>
            <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
                <div class="content">
                    <!--<p>地区：<input type="text" autofocus></p>-->
                    <p>手机号：<input type="number" placeholder="请输入手机号"></p>
                    <p>
                        <span>验证码： </span>
                        <span><input type="text"></span>
                        <span>获取验证码</span>
                    </p>
                    <p><router-link to="/home">登录</router-link></p>
                </div>
            </div>
        </div>
        <!--第三方登录-->
        <div class="else_login">
            <p>-- 其他登录方式 --</p>
            <p>
                <a><img src="../../public/img/timg2.jpg" width="40" alt=""></a>
                <a><img src="../../public/img/timg3.jpg" width="40" alt=""></a>
            </p>
        </div>
    </div>
</template>

<script>
    import bus from '../bus.js'
    // import login from '@/components/login.vue'
    export default {
        name:"login",
        data(){
            return {
                username:'',  //用户账号
                pwd:''        //用户密码
            }
        },
        components:{
        },
        methods:{
            login(){
                if(this.username!=''){   //用户名不为空
                    if(this.pwd!=''){   //密码不为空
                        this.$axios.post('http://localhost:3000/login',"username="+String(this.username)+"&pwd="+String(this.pwd)).then((data) => {
                                // console.log(data);                           
                                if (data.data.code == "200") {
                                    alert(data.data.msg);
                                    // 登录成功将用户名存储到本地
                                    localStorage["user"] =this.username
                                    // this.$axios.post('http://localhost:3000/showCar',"username="+String(this.username)).then((data)=>{
                                    //     console.log(123);
                                    //     this.$store.state.shopCar = JSON.parse(data.data[0].shopCar);
                                    //     localStorage.setItem('shopCar', JSON.stringify(this.$store.state.shopCar)); 
                                    // })
                                    location.href = '/home'
                                }else if(data.data.code == "400"){
                                    alert(data.data.msg);
                                }else if(data.data.code == "404"){
                                    alert(data.data.msg);
                                }
                            }).catch((err) => {
                                console.log(err);
                            })
                    }else{
                        alert("请输入密码")
                    }         
                }else{
                    alert("请输入用户名和密码")
                }
            }
        },
        mounted(){
        }
    }
</script>
<style lang="less" scoped>
    #app_login{
        width: 100%;
        /*padding-bottom:100px ;*/
        position: absolute;
        top: 0;
        bottom: 0;
        background: url("../../public/img/bgc.jpg") no-repeat;
    }
    #myTab{
        display: flex;
        width: 100%;
    }
    /*登录方式部分*/
    #myTab li{
        flex: 1;
        text-align: center;
    }
    /*顶部的登录注册*/
    .top{
        display: flex;
        height: 70px;
        line-height: 70px;
        padding: 0px 25px;
        background: #C25654;
        justify-content: space-between;
    }
    .top a{
        flex: 1;
        text-decoration:none ;
        text-align: right;
        color: white;
    }
    .top span{
        flex: 1;
        font-size: 28px;
        color: white;
    }
    .content{
        padding: 27px;
    }
    /*除了忘记密码*/
    .content p:not(:last-child){
        width: 100%;
        border-bottom: 1px solid #aaa;
    }
    /*忘记密码*/
    .content p:last-child{
        text-align: right;
    }
    .content p input{
        width:80% ;
        height: 35px;
        border: none;
        outline: none;
        background: none;
        padding: 0 10px;
    }
    /*注册部分样式 获取验证码*/
    #profile .content p:nth-child(2){
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    /*验证码文本*/
    .content p:nth-child(2) span:first-child{
        flex: 1;
    }
    /*验证码输入框*/
    .content p:nth-child(2) span:nth-child(2){
        flex: 1.5;
    }
    /*获取验证码*/
    #profile .content p:nth-child(2) span:last-child{
        flex: 1;
        padding: 5px;
        background: #C25654;
        border-radius: 10px;
        outline: none;
        margin-bottom: 10px;
        color: white;
    }
    /*登录按钮*/
    .content p button{
        width: 100%;
        outline: none;
        height: 40px;
        border: 1px solid #ccc;
        border-radius: 10px;
        background:#C25654 ;
        margin-top: 20px;
    }
    /*第三方登录*/
    .else_login{
        text-align: center;
    }
    .else_login p a{
        display: inline-block;
        margin:5px 10px;
        color: black;
    }
</style>
